﻿using System.Data;

namespace CNF.Common.Base.SimpleOrm.Data
{
    public abstract class BaseDbColumn
    {
        protected string name;
        protected int size;
        protected SqlDbType dbType;
        protected string displayName;
        protected bool nullable;

        public string DisplayName
        {
            get { return displayName; }
            set { displayName = value; }
        }

        public bool Nullable
        {
            get { return nullable; }
            set { nullable = value; }
        }

        public string Name
        {
            get { return name; }
        }
        public int Size
        {
            get { return size; }
        }
        public SqlDbType DbType
        {
            get { return dbType; }
        }

        protected BaseDbColumn(string name, int size, SqlDbType dbType, string displayName, bool nullable)
        {
            this.name = name;
            this.size = size;
            this.dbType = dbType;
            this.displayName = displayName;
            this.nullable = nullable;
        }

        public string BulidOrderBy(bool isDesc)
        {
            if (isDesc)
                return string.Format("[{0}] Desc ", this.name);
            else
                return string.Format("[{0}] Asc ", this.name);
        }
 
        public string BulidIsNUllClause()
        {
            return string.Format("([{0}] IS NULL)", this.name);
        }

        public string BulidIsNotNUllClause()
        {
            return string.Format("([{0}] IS NOT NULL)", this.name);
        }


    }
}
